package com.spring.shopping.service.impl;
import com.spring.shopping.entity.Product;
import com.spring.shopping.mapper.ProductMapper;
import com.spring.shopping.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/*
 * @Coding By ZTK:
 */

@Service
@Transactional
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public void addProduct(Product product) {
        productMapper.insertProduct(product);
    }

    @Override
    public List<Product> getAllProducts() {
        return productMapper.selectAllProducts();
    }

    @Override
    public Product getProductById(Integer id) {
        return productMapper.selectProductById(id);
    }

    @Override
    public List<Product> getProductsByUserId(Integer userId) {
        return productMapper.selectProductsByUserId(userId);
    }

    @Override
    public List<Product> getProductsByCategory(String category) {
        return productMapper.selectProductsByCategory(category);
    }
}